package com.mms.handler;

import freemarker.core.Environment;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import java.io.Writer;

/**
 * Created by dan3652@sina.com on 2016-11-24 16:02.
 */
public class FreemarkerExceptionHandler implements TemplateExceptionHandler {
    private static final Log log = LogFactory.getLog(FreemarkerExceptionHandler.class);

    public FreemarkerExceptionHandler() {
    }

    public void handleTemplateException(TemplateException te, Environment env, Writer out) throws TemplateException {
        try {
            out.write("[Error: " + te.getMessage() + "]");
            log.warn("[Freemarker Error: " + te.getMessage() + "]");
        } catch (IOException var5) {
            log.warn(var5.getMessage());
            throw new TemplateException("Failed to print error message. Cause: " + var5, env);
        }
    }
}
